let { tool } = require("../common/main");
let apiService = require("../service/api.service");
let verificationService = require("../service/verification.service");

module.exports = rObject = {
    // 添加日志构造函数
    addLogsAll: class addLogsAll {
        constructor({ phone = "", httpIp = "", type = 1, sys_id = 1 }) {
            this.phone = phone || "";
            this.httpIp = httpIp || "";
            this.type = type || "";
            this.sys_id = sys_id || "";
            this.logsArr = [];
        }
        add(str, status = 0) {
            this.logsArr.push({
                phone: this.phone,
                str: str,
                ip: this.httpIp || "",
                type: this.type,
                status: status,//0为真,1为否
                sys_id: this.sys_id,
                create_time: tool.date(new Date(), "YYYY-MM-DD HH:mm:ss.SSS")
            });
            return this;
        }
        updatePhone(phone = "") {
            this.phone = phone;
            this.logsArr.map(val => {
                val.phone = phone;
            })
        }
        cover(str, status = 0) {
            this.logsArr = [{
                phone: this.phone,
                str: str,
                ip: this.httpIp || "",
                type: this.type,
                status: status,//0为真,1为否
                sys_id: this.sys_id,
                create_time: tool.date(new Date(), "YYYY-MM-DD HH:mm:ss.SSS")
            }];
            return this;
        }
        async select() {
            //console.log(`执行号码的日志->${this.phone}@${tool.date()}`, this.logsArr);
            await apiService.addLogs(this.logsArr);//开始新增日志
            this.logsArr = [];
        }
    },
};
